package de.koller.zero.arch;

public class CTTZNode extends ZNode implements Runnable {
	
	private final Thread thread;
	
	private boolean running = false;
	private final CommandBuffer commands = new CommandBuffer();
	
	public CTTZNode( String threadname ) {
		thread = new Thread( this, threadname );
	}

	public synchronized void start() {
		running = true;
		thread.start();
	}
	
	@Override
	public void run() {
		while( running ) {
			ICommand cmd = commands.getCommand();
			cmd.handleCommand( this );
		}
	}
	
	public void call( ICommand command ) {
		commands.sendCommand( command );
	}
	
	public void stop() {
		running = false;
	}

	public Thread getThread() {
		return thread;
	}
	
}
